package com.marchsoft.group.manager.system.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.marchsoft.group.manager.common.response.Result;

import com.marchsoft.group.manager.common.utils.SecurityUtils;
import com.marchsoft.group.manager.system.entity.User;

import com.marchsoft.group.manager.system.mapper.UserMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ZhangHaoQi
 * @since 2020-12-20
 */
@Api(tags = "用户登陆")
@RestController
@RequestMapping("/api/user")
public class UserController {

    @Autowired
    private UserMapper userMapper;


    @ApiOperation(value = "获取用户的基本信息")
    @ApiImplicitParam(name = "username", value = "姓名", paramType = "query", dataType = "long")
    @GetMapping
    @PreAuthorize("hasAuthority('student')")
    public Result getUser(){
        String username = SecurityUtils.getCurrentUsername();
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("username",Long.parseLong(username)).last("LIMIT 1");
        User user = userMapper.selectOne(queryWrapper);
        return  Result.success(user);
    }
}

